import Ajax from '@/ajax/ajax'
import mockAjax from '@/ajax/mockAjax'
const getCategoryList = () => {
  return Ajax({
    url: '/product/getBaseCategoryList',
    methods: 'get'
  })
}
const getBannerList = () => {
  return mockAjax({
    url: '/banner',
    method: 'get'
  })
}
const getFloor = () => {
  return mockAjax({
    url: '/floor',
    method: 'get'
  })
}
const getGoodsList = (searchParams) => {
  return Ajax({
    url: '/list',
    method: 'post',
    data: searchParams
  })
}
const getGoodDetail = (skuId) => {
  return Ajax({
    url: `/item/${skuId}`,
    method: 'get'
  })
}
//购物车请求
const addToCart = (skuId,skuNum) => {
  return Ajax({
    url: `/cart/addToCart/${skuId}/${skuNum}`,
    method: 'post'
  })
}
const getShopcartList = () => {
  return Ajax({
    url: `/cart/cartList`,
    method: 'get'
  })
}
//修改商品选中状态
const changeCartChecked = (skuID,isChecked) => {
  return Ajax({
    url: `/cart/checkCart/${skuID}/${isChecked}`,
    method: 'get'
  })
}
const changeAllChecked = (isChecked,skuIds) => {
  return Ajax({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: 'post',
    data: skuIds
  })
}
const deleteOneCart = (skuId) => {
  return Ajax({
    url: `/cart/deleteCart/${skuId}`,
    method: 'delete'
  })
}
const deleteCheckedCart = (skuIds) => {
  return Ajax({
    url: `/cart/batchDeleteCart`,
    method: 'delete',
    data: skuIds
  })
}
const registerUser = (userObj) => {
  return Ajax({
    url: '/user/passport/register',
    method: 'post',
    data: userObj
  })
}
const sendCode = (phone) => {
  return Ajax({
    url: `/user/passport/sendCode/${phone}`,
    method: 'get'
  })
}
const loginUser = (userObj) => {
  return Ajax({
    url: `/user/passport/login`,
    method: 'post',
    data: userObj
  })
}
const getUserInfo = () => {
  return Ajax({
    url: `/user/passport/auth/getUserInfo`,
    method: 'get'
  })
}
const getOrderInfo = () => {
  return Ajax({
    url: `/order/auth/trade`,
    method: 'get'
  })
}
const getUserAddress = () => {
  return Ajax({
    url: `/user/userAddress/auth/findUserAddressList`,
    method: 'get'
  })
}
const submitOrder = (tradeNo,userInfo) => {
  return Ajax({
    url: `/order/auth/submitOrder?tradeNo=${tradeNo}`,
    method: 'post',
    data: userInfo
  })
}
const getPayInfo = (orderId) => {
  return Ajax({
    url: `/payment/weixin/createNative/${orderId}`,
    method: 'get'
  })
}
const searchPayStatus = (orderId) => {
  return Ajax({
    url: `/payment/weixin/queryPayStatus/${orderId}`,
    method: 'get'
  })
}
const getMyOrderList = (page,limit) => {
  return Ajax({
    url: `/order/auth/${page}/${limit}`,
    method: 'get'
  })
}
export {
  getCategoryList,
  getBannerList,
  getFloor,
  getGoodsList,
  getGoodDetail,
  addToCart,
  getShopcartList,
  changeCartChecked,
  changeAllChecked,
  deleteOneCart,
  deleteCheckedCart,
  registerUser,
  sendCode,
  loginUser,
  getUserInfo,
  getOrderInfo,
  getUserAddress,
  submitOrder,
  getPayInfo,
  searchPayStatus,
  getMyOrderList
}
